/*
 * Jamus
 * Copyright (C) 2010 Jamus Team
 *
 * Jamus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Jamus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Jamus.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <stdexcept>

#include "Track.h"

using namespace std;
using boost::posix_time::time_duration;

Track::Track()
: trackNumber(0)
{
}

Track::Track(const string& fileName, const time_duration& duration)
: fileName(fileName), duration(duration), trackNumber(0)
{
}

Track::Track(const string& fileName, const time_duration& duration, const std::string& artist, const std::string& album, const std::string& title, int trackNumber)
: fileName(fileName), duration(duration), artist(artist), album(album), title(title), trackNumber(trackNumber)
{
}

bool Track::matches(const string& attribute, const string& value) const
{
	if(boost::iequals(attribute, "artist"))
		return artist == value;
	if(boost::iequals(attribute, "album"))
		return album == value;
	if(boost::iequals(attribute, "title"))
		return title == value;
	if(boost::iequals(attribute, "trackNumber"))
		return trackNumber == boost::lexical_cast<int>(value);

	throw runtime_error("Unknown attribute");
}

const string& Track::getFileName() const
{
	return fileName;
}

void Track::setFileName(const string& fileName)
{
	this->fileName = fileName;
}

const time_duration& Track::getDuration() const
{
	return duration;
}

void Track::setDuration(const time_duration& duration)
{
	this->duration = duration;
}

const string& Track::getArtist() const
{
	return artist;
}

void Track::setArtist(const string& artist)
{
	this->artist = artist;
}

const string& Track::getAlbum() const
{
	return album;
}

void Track::setAlbum(const string& album)
{
	this->album = album;
}

const string& Track::getTitle() const
{
	return title;
}

void Track::setTitle(const string& title)
{
	this->title = title;
}

int Track::getTrackNumber() const
{
	return trackNumber;
}

void Track::setTrackNumber(int trackNumber)
{
	this->trackNumber = trackNumber;
}

bool Track::operator==(const Track& t) const
{
	return fileName == t.fileName
		&& duration == t.duration
		&& artist == t.artist
		&& album == t.album
		&& title == t.title
		&& trackNumber == t.trackNumber;
}

